package com.example.demo.feign;

import com.netflix.hystrix.HystrixCommand;
import feign.Feign;
import feign.RequestInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.support.SpringMvcContract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class FeignClientConfig {

    @Bean
    public RequestInterceptor requestInterceptor(){
        Feign feign = Feign.builder()
                .build();
        DefaultFeignClient target = Feign.builder().contract(new SpringMvcContract()).target(DefaultFeignClient.class, "https://www.baidu.com");
        return requestTemplate -> requestTemplate.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36 Edg/86.0.622.61");
    }

    public static void main(String[] args) {
        DefaultFeignClient target = Feign
                .builder()
                .contract(new SpringMvcContract())
                .target(DefaultFeignClient.class, "https://www.baidu.com");
        HystrixCommand<String> aa = target.search3("aa");
    }
}